<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
    <meta name="description" content="">
    <meta name="author" content="">


    <title>Signin Template for Bootstrap</title>

    <!-- Bootstrap core CSS -->
    <link href="css/bootstrap.min.css" rel="stylesheet">

    <!-- Custom styles for this template -->
    <link href="css/signin.css" rel="stylesheet">
    <script src="https://unpkg.com/vue@2.7.14/dist/vue.min.js"></script>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <link href="css/bootstrap.css" rel="stylesheet">
    <link href="css/bootstrap-theme.css">

</head>

<body>

<div class="container" id="app">

    <form class="form-signin">
        <h2 class="form-signin-heading">Please sign in</h2>
        <label for="inputUSerNAme" class="sr-only">Administrator name</label>
        <input id="inputUSerNAme" class="form-control" v-model="raname" placeholder="Administrator name" required
               autofocus>
        <label for="inputPassword" class="sr-only">Password</label>
        <input type="password" id="inputPassword" v-model="rapwd" class="form-control" placeholder="Password" required>
        <div class="checkbox">
            <label>
                <input type="checkbox" value="remember-me"> Remember me
            </label>
        </div>
        <button class="btn btn-lg btn-primary btn-block" @click="login()">Sign in</button>
    </form>

</div> <!-- /container -->

</body>

<script>
    let vm = new Vue({
        el: "#app",
        data: {
            raname: 'a',
            rapwd: 'a',
        },
        methods: {
            login: function () {
                console.log('Login button clicked');
                const params = new URLSearchParams();
                params.append("raname", this.raname);
                params.append("rapwd", this.rapwd);

                axios.post("resadmin/login", params)
                    .then(res => {
                        var user = res.data;
                        if (user.code !== 200) {
                            alert(user.msg);
                        } else {
                            console.log('Redirecting to adminBoarg.html');
                            location.href = './back/foodControl.html';
                        }
                    })
                    .catch(error => {
                        console.error('Error:', error);
                    });
            },


        },
    })
</script>
</html>